# Maintainer: Simon Zeni <simon@bl4ckb0ne.ca>
pkgname=mold
pkgver=2.34.1
pkgrel=0
pkgdesc="fast modern linker"
url="https://github.com/rui314/mold"
arch="all"
license="MIT"
makedepends="
	cmake
	linux-headers
	mimalloc2-dev
	onetbb-dev
	samurai
	zlib-dev
	zstd-dev
	"
checkdepends="
	bash
	dwarf-tools
	grep
	"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/rui314/mold/archive/refs/tags/v$pkgver.tar.gz"

build() {
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON \
		-DMOLD_LTO=ON \
		-DMOLD_USE_SYSTEM_MIMALLOC=ON \
		-DMOLD_USE_SYSTEM_TBB=ON \
		-DBUILD_TESTING="$(want_check && echo ON || echo OFF)"

	cmake --build build
}

check() {
	# s390x-shared-abs-sym and riscv64-shared-abs-sym are broken
	case "$CARCH" in
		s390x) ctest --output-on-failure --test-dir build -E s390x-shared-abs-sym;;
		riscv64) ctest --output-on-failure --test-dir build -E riscv64-shared-abs-sym;;
		*) ctest --output-on-failure --test-dir build;;
	esac
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
6ddfda8b81b710555272ee67eac7f2b3088a7a78f308843caa1730c1b631fc7031b8f5eac33379b9926c9f000d7b27864c12bb62ea75051d2f1caf9f9d2946ab  mold-2.34.1.tar.gz
"
